package jp.co.irep.juten.utils;

import java.util.ResourceBundle;
import javax.faces.application.FacesMessage;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;

public class BeanUtil {

    /**
     * エラーを表示する
     * @param type
     * @param err
     */
    public static void setMessage(String type, String mess) {
        FacesMessage message = null;
        if (type.equals(Consts.ERROR)) {
            message = new FacesMessage(FacesMessage.SEVERITY_ERROR, mess, "");
        }
        if (type.equals(Consts.INFO)) {
            message = new FacesMessage(FacesMessage.SEVERITY_INFO, mess, "");
        }
        if (type.equals(Consts.WARNING)) {
            message = new FacesMessage(FacesMessage.SEVERITY_WARN, mess, "");
        }
        FacesContext.getCurrentInstance().getExternalContext().getFlash().setKeepMessages(true);
        FacesContext.getCurrentInstance().addMessage(null, message);

    }

    /**
     * 
     * @param key
     * @return 
     */
    public static String getMessageString(String key) {
        FacesContext context = FacesContext.getCurrentInstance();
        ResourceBundle bundle = ResourceBundle.getBundle(context.getApplication().getMessageBundle());
        return bundle.getString(key);
    }

    /**
     * WEBINFパス取得
     *
     * @return
     */
    public static String getWebInfPath() {
        ExternalContext extContext = FacesContext.getCurrentInstance()
                .getExternalContext();
        return extContext.getRealPath("//WEB-INF");
    }

}
